﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using ContractManager.Data;
using ContractManager.Data.Base;
using Repository;
using Speed.Data;

namespace ContractManager.Test
{
    public partial class Form1 : Form
    {
       // readonly ContractContext _context = new ContractContext();
        UnitOfWork _unitOfWork ;

        public Form1()
        {
            InitializeComponent();
        }

        private void GetCaptials()
        {
            //var capitals =
            //    _unitOfWork.Repository<Capitals>().Query().Get().AsQueryable();

            //this.gridControl1.DataSource = capitals.ToList();
        }

        private void GetData()
        {
            using (var db = Sys.NewDb())
            {
                var captial = ContractManager.Data.Base.Capitals.Select(db);
                //var list = db.Select<ContractManager.Data.Base.Capitals>();
                /*foreach (var cap in captial)
                {
                    if (cap.CapId.Equals(1)) cap.CapCode = "100102";
                    ContractManager.Data.Base.Capitals.Update(db, cap);
                }*/
                //var captial2 = ContractManager.Data.Base.Capitals.Select(db);
                this.gridControl1.DataSource = captial;
                
            }

            
        }
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            GetCaptials();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //_unitOfWork = new UnitOfWork(_context);

            Sys.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ContractContext"].ConnectionString;
            Sys.CommandTimeout = 10000;
            Sys.ProviderType = EnumDbProviderType.SqlServer;
            
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            var data = (IEnumerable<Capitals>)this.gridControl1.DataSource;
            //foreach (Capitals item in data)
            //{
            //    MessageBox.Show(item.State.ToString());
            //}
            //_unitOfWork.Save();
        }

        private void simpleButton3_Click(object sender, EventArgs e)
        {
            GetData();
        }
    }
}
